package com.example.controller;

import com.example.common.Result;
import com.example.entity.Message;
import com.example.service.MessageService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 反馈建议(Message)表控制层
 */
@CrossOrigin//解决跨域问题
@RestController
public class MessageController {
    
    @Resource
    private MessageService messageService;
    
    // 信息列表
    @ResponseBody
    @RequestMapping("messageList")
    public Result messageList(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum,
                             @RequestParam(defaultValue = "1", value = "pageSize") Integer pageSize,
                             HttpServletRequest request) {
        String key = request.getParameter("key");
        String memberid = request.getParameter("memberid");
        
        PageInfo<Message> pageInfo = messageService.getMessageList(pageNum, pageSize, key, memberid);
        return Result.success(pageInfo);
    }
    
    // 添加或编辑信息
    @ResponseBody
    @RequestMapping("messageAdd")
    public Result messageAdd(Message message, HttpServletRequest request) {
        messageService.saveOrUpdate(message);
        return Result.success();
    }
    
    // 删除信息
    @ResponseBody
    @RequestMapping("messageDel")
    public Result messageDel(int id, HttpServletRequest request) {
        messageService.deleteMessage(id);
        return Result.success();
    }
    
    // 批量删除信息
    @ResponseBody
    @RequestMapping("messageDeleteAll")
    public Result typeDeleteAll(HttpServletRequest request) {
        String vals = request.getParameter("vals");
        messageService.batchDeleteMessage(vals);
        return Result.success();
    }
}

